<?php
    class user extends Zend_Form
    {
        public function __construct($options = null) 
        {
            parent :: __construct($options);
            
            $db = db();
            
            $css = array(
                'ViewHelper',
                'Errors',
                array('HtmlTag', array('tag' => 'td')),
                array('Label', array('tag' => 'th')),
                array(array('tr' => 'HtmlTag'), array('tag' => 'tr'))
            );
            
            $q = "SELECT id, nom FROM roles";
            $res = $db -> fetchArray($q);
            $roles = array();
            $roles[''] = __('Choisir');
            foreach ($res as $row)
                $roles[$row['id']] = $row['nom'];
            
            formHidden($this, 'token', token());
            formSelect($this, 
                'actif', 
                'Actif', 
                true, 
                array(
                    '' => __('Choisir'),
                    1 => __('Oui'),
                    2 => __('Non')
                )
            );
            
            formSelect($this, 
                'langue', 
                'Langue', 
                true, 
                array(
                    '' => __('Choisir'),
                    'fr' => __('Français'),
                    'en' => __('Anglais'),
                    'es' => __('Espagnol')
                )
            );
            
            formSelect($this, 
                'role', 
                'Rôle', 
                true, 
                $roles
            );
            
            formInput($this, 'login', 'Identifiant');
            formPassword($this, 'mdp', 'Mot de passe');
            formInput($this, 'nom', 'Nom');
            formInput($this, 'prenom', 'Prénom');
            formInput($this, 'courriel', 'Courriel');
            
            // $c = captcha();
            
            $actionController = getvar('**action**');
            switch ($actionController)
            {
                case 'add':
                    $submit = new Zend_Form_Element_Submit('Ajouter');
                    $submit -> setLabel(__('Ajouter'));
                    break;
                case 'edit':
                    $submit = new Zend_Form_Element_Submit('Editer');
                    $submit -> setLabel(__('Mettre à jour'));
                    break;
                case 'dup':
                    $submit = new Zend_Form_Element_Submit('Dupliquer');
                    $submit -> setLabel(__('Dupliquer'));
                    break;
            }
            
            $submit -> setDecorators(array(
                'ViewHelper',
                array(array('td' => 'HtmlTag'), array('tag' => 'td', 'colspan' => 2)),
                array(array('tr' => 'HtmlTag'), array('tag' => 'tr'))
            ));
            $submit -> setAttrib('class', 'submit mid');
            
            $this   -> setAction(makeUrl('user', $actionController))
                    -> setDecorators(
                            array(
                                'FormElements',
                                array('HtmlTag', array('tag' => 'table')),
                                'Form'
                            )
                        )
                    -> setAttrib('class', 'submit')
                    -> setMethod('post')
                    -> addElement($submit);
        }
    }
?>